//
//  XJWalletAddZFBAccountViewController.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/23.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJWalletAddZFBAccountViewController.h"
#import "XJLabelTextField.h"

@interface XJWalletAddZFBAccountViewController ()
@property(nonatomic, strong) XJLabelTextField *zfbNameTF;
@property(nonatomic, strong) XJLabelTextField *zfbAccountTF;
@property(nonatomic, strong) UIButton *submitButton;


@end

@implementation XJWalletAddZFBAccountViewController


#pragma mark - lazy
- (XJLabelTextField *)zfbNameTF {
    if (!_zfbNameTF) {
        _zfbNameTF = [[XJLabelTextField alloc] initWithFrame:CGRectMake(15, 0, KWidth-15, 50) keyType:(UIKeyboardTypeDefault) textEntry:NO leftTitle:@"支付宝姓名" placeholder:@"请输入"];
    }
    return _zfbNameTF;
}

- (XJLabelTextField *)zfbAccountTF {
    if (!_zfbAccountTF) {
        _zfbAccountTF = [[XJLabelTextField alloc] initWithFrame:CGRectMake(15, 50+10, KWidth-15, 50) keyType:(UIKeyboardTypeNumberPad) textEntry:NO leftTitle:@"支付宝账号" placeholder:@"请输入"];
    }
    return _zfbAccountTF;
}

- (UIButton *)submitButton {
    if (!_submitButton) {
        _submitButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        
        
        _submitButton.frame = CGRectMake(30, 300, KWidth - 60, 50);
        [_submitButton setTitle:@"提交" forState:(UIControlStateNormal)];
        [_submitButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        _submitButton.layer.masksToBounds = YES;
        _submitButton.layer.cornerRadius  = 10;
        _submitButton.backgroundColor = XJCOLOR_RGB(255, 216, 68);
        
        [_submitButton addTarget:self action:@selector(submitButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    
    return _submitButton;
}

- (void)submitButtonAction {
    XJLog(@"提交");
    
    NSString *customer_name = self.zfbNameTF.text;
    NSString *pay_name = self.zfbAccountTF.text;
    NSNumber *type = @(0);
    if ([NSString isEmptyString:customer_name]) {
        [JRToast showWithText:@"未来巴扎:请输入支付宝姓名"];
        return;
    }
    if ([NSString isEmptyString:customer_name]) {
        [JRToast showWithText:@"未来巴扎:请输入支付宝账号"];
        return;
    }
    
    
    
    
    NSDictionary *parDic = NSDictionaryOfVariableBindings(customer_name,pay_name,type);
    
    [self requestAddZFBWithDic:parDic];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navTitle = @"添加支付宝账号";
    
    [self.view addSubview:self.zfbNameTF];
    [self.view addSubview:self.zfbAccountTF];
    [self.view addSubview:self.submitButton];
    
}


#pragma mark - 网络请求
- (void)requestAddZFBWithDic:(NSDictionary *)dic {
    
    [XJHttpTool requestCustomAccountAddAccountWithParDic:dic successH:^(id responseObjc) {
        
        NSString *code = [NSString stringWithFormat:@"%@",responseObjc[@"code"]];
        if ([code isEqualToString:@"0"]) {
            
            [JRToast showWithText:@"添加银行卡成功"];
            //返回
            [self.navigationController popViewControllerAnimated:YES];
        }else {
            [JRToast showWithText:responseObjc[@"message"]];
        }
    } failH:^(NSError *error) {
        [JRToast showWithText:[error localizedDescription]];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
